package com.baoming.util;

/**
 * @author Administrator
 *
 * TODO To change the template for this generated type comment go to
 * Window - Preferences - Java - Code Style - Code Templates
 */
import javax.servlet.http.HttpServletRequest;

public class PageInfo {
	
	private HttpServletRequest request;
	private int pageSize = 15;
	private int currentPageNow = 0;
	private int beginResult = 0;
	private int totalResult = 0;
	private int totalPage = 0;

	private PageBean page = null;

	public PageInfo(HttpServletRequest request) {
		this.currentPageNow = request.getParameter("pager.offset") != null
				&& !request.getParameter("pager.offset").equals("0") ? new Integer(
				request.getParameter("pager.offset")).intValue()
				: 0; 
		this.setRequest(request);
	}
 
	public PageInfo(int currentPageNo) {

		this.currentPageNow = currentPageNo;
		this.pageSize = 10;

	}

	private void countPages() {
		this.totalPage = (totalResult / pageSize); 
		if ((totalResult % pageSize) != 0)
			this.totalPage = this.totalPage + 1;
	}

	public int getCurrentPageNow() {
		return currentPageNow;
	}

	public int getPageSize() {
		setRequestValue();
		return pageSize;
	}

	public int getTotalResult() {
		return totalResult;
	}

	public void setCurrentPageNow(int current) {
		this.currentPageNow = current;
	}

	public void setPageSize(int i) {
		this.pageSize = i;
	}

	public int getBeginResult() {
		
		return beginResult;
	}

	public void setBeginResult(int beginResult) {
		this.beginResult = beginResult;
	}

	public int getTotalPage() {
		return totalPage;

	}

	public void setTotalResult(int totalResult) {
		this.totalResult = totalResult;
		countPages();
	}

	private void setRequestValue() {
		page = new PageBean();
		page.setPageNow(currentPageNow);
		page.setPageSize(pageSize);
		page.setSumPage(totalPage);
		page.setTotalResult(totalResult);

	}

	public PageBean getPageBean() {
		return page;
	}

	public void setTotalPage(int totalPage) {
		this.totalPage = totalPage;
	}

	public void setRequest(HttpServletRequest request) {
		this.request = request;
	}

	public HttpServletRequest getRequest() {
		return request;
	}

}
